<template>
	<my-popup ref="pop_share" height='150' title='分享方式'>
		<view class="flex">
			<!-- #ifdef MP-WEIXIN -->
			<view class="pad10 item relative flex a-c j-c">
				<view>
					<view class="i-weixin iconfont"></view>
					<view class="padv10 text">好友</view>
				</view>
				<button open-type="share" style="width: 100%;height: 100rpx;top:10rpx;background-color: transparent;"
					class="absolute"></button>
			</view>
			<!-- #endif -->
			<!-- #ifdef H5  || APP-VUE -->
			<view class="pad10 item " @click="copy">
				<view class="i-fuzhilianjie iconfont"></view>
				<view class="padv10 text">复制链接</view>
			</view>
			<!-- #endif -->
			<view class="pad10 item" v-if="poster" @click="showPoster">
				<view class="i-haibao iconfont"></view>
				<view class="padv10 text">海报</view>
			</view>
		</view>
	</my-popup>
</template>

<script>
	export default {
		name: "sb-share-panel",
		props: {
			poster: {
				type: String
			}
		},
		methods: {
			show() {
				this.$refs.pop_share.show()
			},
			hide() {
				this.$refs.pop_share.hide()
			},
			copy(e) {
				this.$copy(process.uni_env.HOST + '/' + this.currentRoute())
			},
			showPoster() {
				uni.showLoading()
				// #ifdef MP-WEIXIN || APP-VUE
				uni.downloadFile({
					url: this.poster,
					success: (res) => {
						uni.showShareImageMenu({
							path: res.tempFilePath
						})
					},
					fail(e) {
						console.log(e);
					},
					complete() {
						uni.hideLoading()
					}
				})
				// #endif
				// #ifdef H5
				uni.previewImage({
					current: 0,
					urls: [this.poster],
					success() {
						uni.hideLoading()
					}
				})
				// #endif
			},
		},
	}
</script>

<style lang="scss" scoped>
	.item {
		width: 20%;
		color: #666;

		.text {
			font-size: 24rpx;
			color: #404040;
		}

		.iconfont {
			font-size: 46rpx;
		}
	}
</style>
